﻿using System;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for WegoHotelsRateDB
/// </summary>
/// 
namespace CE.Wego
{
    public class WegoHotelsRateDB
    {
        public WegoHotelsRateDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }


        public Int64 Insert(WegoHotelsRateInfo wegorateinfo)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocWegoHotelsRateInsertSingleItem";

             SortedList _sPara = new SortedList();
            #region Parameter
             _sPara.Add("@HotelsId", wegorateinfo.HotelsId);
             _sPara.Add("@Price", wegorateinfo.Price);
             _sPara.Add("@Tax ", wegorateinfo.Tax);
             _sPara.Add("@On_Request", wegorateinfo.OnRequest);
             _sPara.Add("@Description", wegorateinfo.Description);
             _sPara.Add("@Partner", wegorateinfo.Partner);
             _sPara.Add("@KeyId", wegorateinfo.KeyId);

            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public DataTable GetWegoHotelRates(Int64 HotelsId)
        {
            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable("HotelList");
            string _spName = "sprocWegoHotelsRateSelectItem";
            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@HotelsId", HotelsId);
            #endregion

            _dtResult = _db.GetDataTableBySP(_spName, _sPara);
            return _dtResult;
        }


        public DataTable GetWegoHotelRatesDetailsByPrice(Int64 HotelsId, float Price)
        {
            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable("HotelRates");
            string _spName = "sprocWegoHotelsRateSelectItemByHotelPrice";
            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@HotelsId", HotelsId);
            _sPara.Add("@Price", Price);
            #endregion

            _dtResult = _db.GetDataTableBySP(_spName, _sPara);
            return _dtResult;
        }


        public int GetWegoHotelRatesDistinctPartners(Int64 HotelsId)
        {
            int PartnerCount = 0;

            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable("HotelList");
            string _spName = "[sprocWegoHotelsRateSelectDistinctPartners]";
            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@HotelsId", HotelsId);
            #endregion

            _dtResult = _db.GetDataTableBySP(_spName, _sPara);

            if (_dtResult.Rows.Count > 0)
            {
                PartnerCount = int.Parse(_dtResult.Rows[0]["NoOfSites"].ToString());
            }
            return PartnerCount;
        }


        private WegoHotelsRateInfo FillDataRecord(DataTable myDataTable, int rowId)
        {
            WegoHotelsRateInfo wegohotels = new WegoHotelsRateInfo();
            wegohotels.RateId = Convert.ToInt64(myDataTable.Rows[rowId]["RateId"].ToString());
            wegohotels.HotelsId = Convert.ToInt32(myDataTable.Rows[rowId]["HotelsId"].ToString());
            wegohotels.Price = float.Parse(myDataTable.Rows[rowId]["Price"].ToString());
            wegohotels.Tax = bool.Parse(myDataTable.Rows[rowId]["Tax"].ToString());
            wegohotels.OnRequest = bool.Parse(myDataTable.Rows[rowId]["On_Request"].ToString());
            wegohotels.Description = myDataTable.Rows[rowId]["Description"].ToString();
            wegohotels.Partner = myDataTable.Rows[rowId]["Partner"].ToString();
            wegohotels.KeyId = myDataTable.Rows[rowId]["KeyId"].ToString();

            return wegohotels;
        }

    }
}